package com.wc.AlgoOJ._图论.Dijkstra.blg穿越了;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/11/2 13:31
 * @description http://43.138.190.70:8888/p/CT0214
 */
public class Main {
    // 需要状态压缩一下
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 5010, M = 200010, K = 1 << 10, INF = 0x3f3f3f3f << 1;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    // 每个点的道具
    static int[] s = new int[N], base = new int[K];
    static int[][] dist = new int[N][K];
    static boolean[][] st = new boolean[N][K];
    static PriorityQueue<int[]> heap = new PriorityQueue<>(Comparator.comparingInt(o -> o[0]));
    static int n, m, k, idx = 1;

    public static void main(String[] args) {
        base[0] = 1;
        for (int i = 1; i < K; i++) base[i] = base[i - 1] << 1;
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        for (int i = 1; i < n; i++) s[i] = sc.nextInt();
        dijkstra();
        for (int i = 1; i < n; i++) {
            int res = INF;
            for (int j = 0; j < 1 << k; j++) res = Math.min(res, dist[i][j]);
            out.println(res == INF ? -1 : res);
        }
        out.flush();
    }

    static void dijkstra() {
        for (int i = 0; i <= n; i++) Arrays.fill(dist[i], INF);
        dist[0][0] = 0;
        heap.add(new int[]{0, 0, 0});
        while (!heap.isEmpty()) {
            int[] t = heap.poll();
            int d = t[0], u = t[1], state = t[2];
            if (st[u][state]) continue;
            st[u][state] = true;
            for (int i = h[u]; i > 0; i = ne[i]) {
                int j = e[i];
                int x = cnt(state);
                if (s[j] == 0) {
                    if (!st[j][state] && d + (w[i] + base[x] - 1) / base[x] < dist[j][state]) {
                        dist[j][state] = d + (w[i] + base[x] - 1) / base[x];
                        heap.add(new int[]{dist[j][state], j, state});
                    }
                } else {
                    if (!st[j][state | (1 << s[j] - 1)] && d + (w[i] + base[x] - 1) / base[x] < dist[j][state | (1 << s[j] - 1)]) {
                        dist[j][state | (1 << s[j] - 1)] = d + (w[i] + base[x] - 1) / base[x];
                        heap.add(new int[]{dist[j][state | (1 << s[j] - 1)], j, state | (1 << s[j] - 1)});
                    }
                }
            }
        }
    }

    static int cnt(int x) {
        int res = 0;
        for (int i = 0; i < k; i++) {
            res += x >> i & 1;
        }
        return res;
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
